package tcards.android;

import models.ResourceTcard;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public class ResourceFieldList extends LinearLayout {
	private GeneralFieldList mGeneralList;
	private GroupFieldList   mGroupList;
	private TextField        mLeaderName;
	private TextField        mContactInfo;
	private MultiField       mResourceNames;
	
	public ResourceFieldList(Context context) {
		this(context, null, 0);
	}

	public ResourceFieldList(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public ResourceFieldList(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.resource_field_list, this, false));
		
		mGeneralList   = (GeneralFieldList) findViewById(R.id.resourceGeneralList);
		mGroupList     = (GroupFieldList)   findViewById(R.id.resourceGroupList);
		mLeaderName    = (TextField)        findViewById(R.id.leaderNameField);
		mContactInfo   = (TextField)        findViewById(R.id.contactInfoField);
		mResourceNames = (MultiField)       findViewById(R.id.resourceNamesField);
	}
	
	public void setTcardFields(ResourceTcard tcard) {
		mGeneralList.setTcardFields(tcard);
		mGroupList.setTcardFields(tcard);
		tcard.setLeaderName(mLeaderName.getTextValue());
		tcard.setPrimaryContactInfo(mContactInfo.getTextValue());
		tcard.setResourceNames(mResourceNames.getTextValue());
	}
	
	public void setListFields(ResourceTcard tcard) {
		mGeneralList.setListFields(tcard);
		mGroupList.setListFields(tcard);
		mLeaderName.setTextValue(tcard.getLeaderName());
		mContactInfo.setTextValue(tcard.getPrimaryContactInfo());
		mResourceNames.setTextValue(tcard.getResourceNames());
	}
	
	public GeneralFieldList getGeneralList() {
		return mGeneralList;
	}
	
	public GroupFieldList getGroupList() {
		return mGroupList;
	}
	
	public TextField getLeaderName() {
		return mLeaderName;
	}
	
	public TextField getContactInfo() {
		return mContactInfo;
	}
	
	public MultiField getResourceNames() {
		return mResourceNames;
	}
}